package com.dek.zk;

import org.I0Itec.zkclient.IZkDataListener;

public class DataChangeListener {

    private static class ZKDataListener implements IZkDataListener {

        @Override
        public void handleDataChange(String dataPath, Object data) throws Exception {
            System.out.println(dataPath + " is updated");
            NodeData nodeData = (NodeData) data;
            System.out.println(nodeData.getId());
            System.out.println(nodeData.getName());
        }

        @Override
        public void handleDataDeleted(String dataPath) throws Exception {
            System.out.println(dataPath + " is deleted!");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        CreateSession.getClient().subscribeDataChanges("/testData", new ZKDataListener());
        Thread.sleep(Integer.MAX_VALUE);
    }

}
